﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Web;

namespace DuelQuizzServer
{
    [DataContract]
    public class Party
    {
        /* parties members */
        private static List<Party> parties = new List<Party>();
        public static List<Party> Parties { get { return parties; } }

        /* party memebers */
        [DataMember]
        private int id;     
        public int Id { get { return id; } }

        [DataMember]
        private string title;
        public string Title { get { return title; } set { title = value; } }
        
        [DataMember]
        private List<User> player_list = new List<User>();
        public List<User> Player_list { get { return player_list; } }

        internal Party(int party_id, string title)
        {
            this.id = party_id;
            this.title = title;
            parties.Add(this);
        }

        internal static Party find(int party_id){
            foreach(Party party in parties){
                if(party.id == party_id)
                    return party;
            }

            return null;
        }


        internal void addPlayer(User user) { addPlayer(user.id); }
        internal void addPlayer(int player_id)
        {
            try
            {
                User player = new User(player_id);
                player_list.Add(player);
            }
            catch (Exception e) { 
                 
            }
        
        }

        internal void removePlayer(int player_id)
        {
            for (int i = 0; i < player_list.Count; i++)
            {
                if (player_list[i].id == player_id)
                {
                    player_list.RemoveAt(i);
                }
            }
        }

        internal void startGame() { }
        internal void endGame() { }

        public override string ToString(){ return Title;}
    }
}